﻿using UnityEngine;
using System.Collections;
using Common;


public class bgMode :  MonoBehaviour
{

    void Start()
    {
        float cameraSize = Camera.main.orthographicSize;

        SpriteRenderer spriteRender = this.transform.GetComponent<SpriteRenderer>();
        if (spriteRender == null) Debug.LogError("No Such Component");
        float spriteWith = spriteRender.bounds.size.x;
        float spriteHeigt = spriteRender.bounds.size.y;

        float screenW = Screen.width;
        float screenH = Screen.height;

        float screenRato = screenW * 1.0f / screenH;

        float cameraW = cameraSize * 2 * screenRato;

        this.transform.localScale = new Vector3(cameraW*1.0f/spriteWith,1,1);

//         float devHeight = 8.0f;
//         float devWidth = 4.8f;
// 
// 
//         float screenHeight = Screen.height;
// 
//         float orthographicSize = Camera.main.orthographicSize;
// 
//         float aspectRatio = Screen.width * 1.0f / Screen.height;
// 
//         float cameraWidth = orthographicSize * 2 * aspectRatio;
// 
//         if (cameraWidth < devWidth)
//         {
//             orthographicSize = devWidth / (2 * aspectRatio);
//             Debug.Log("new orthographicSize = " + orthographicSize);
//             this.GetComponent<Camera>().orthographicSize = orthographicSize;
//         }
    }
	
}
